package com.pat.jrgwt.client;

import org.eclipse.jdt.internal.compiler.ast.Argument;

import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;

public class PosSizeMultMinMove extends Composite
{

    protected NumberFormat m_nf = NumberFormat.getFormat("###,###");
    protected String[] m_arExchanges = new String[] { "EURUSD", "AUDJPY", "USDJPY", "USDJPY", "GBPJPY", "EURNZD" };
    protected double[] m_posSizeMinMove = new double[] { 10, 1000, 1000, 1000, 1000, 10 };
    
    private static class SingletonHolder
    {
        private static final PosSizeMultMinMove instance = new PosSizeMultMinMove();
    }
    
    public static PosSizeMultMinMove getInstance()
    {
        return SingletonHolder.instance;
    }
    
    private PosSizeMultMinMove()
    {
        HorizontalPanel p = new HorizontalPanel();

        Label lbl = new Label("pos.zise * min.move");
        lbl.setStylePrimaryName("cellBold");
        p.add(lbl);
        
        for (int i = 0; i < m_posSizeMinMove.length; i++)
        {
            TextBox tb = new TextBox();
            tb.setText(m_nf.format(m_posSizeMinMove[i]));
            tb.setReadOnly(true);
            tb.setWidth("95px");
            p.add(tb);
        }
        
        initWidget(p);
    }

    /**
     * Returns ratio for this currency exchange
     * @param exchangeName
     * 
     * @throws Exception if currency was not found
     */
    public double getValue(String exchangeName) throws Exception
    {
        exchangeName = exchangeName.toUpperCase();
        for (int i = 0; i < m_arExchanges.length; i++)
        {
            if( exchangeName.startsWith(m_arExchanges[i]) )
            {
                return m_posSizeMinMove[i];
            }
        }
        
        throw new Exception("Currency exchange " + exchangeName + " was not found!");
    }
    
}
